Rec 'n' Replay/Mfrm.frm
VERSION 5.00
Begin VB.Form Mfrm
BorderStyle = 1 'Fest Einfach
Caption = "Rec 'n' Replay ‑ (c)2004 by Louis."
ClientHeight = 7335
ClientLeft = 45
ClientTop = 420
ClientWidth = 10395
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 7335
ScaleWidth = 10395
StartUpPosition = 3 'Windows‑Standard
Begin VB.CommandButton Command2
Caption = "Replay"
BeginProperty Font
Name = "Arial"
Size = 99.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3615
Left = 0
TabIndex = 2
Top = 3720
Width = 10395
End
Begin VB.CommandButton Command3
Caption = "Fill with sin()‑wave"
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 555
Left = 0
TabIndex = 1
Top = 3180
Width = 10395
End
Begin VB.CommandButton Command1
Caption = "Rec"
BeginProperty Font
Name = "Arial"
Size = 99.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3135
Left = 0
TabIndex = 0
Top = 60
Width = 10395
End
End
Attribute VB_Name = "Mfrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'(c)2003, 2004 by Louis. Modules of this project copied from general function library on 02.12.03
'(do not use these modules here for new projects (note not valid for downloadable version)).
'
'Downloaded from www.louis‑coder.com.
'Records a short sample from the microphone, saves it in memory and replays it.
'You can easily manipulate the wave data within the buffer, for e.g. creating noises for simple
'games, or any other suitable usage. Please note that the sample works best for 44 KHz and 16
'bit sampling rate. If you need other sampling frequencies or ‑rates, then extend code on your
'own (sorry, the current functionality was sufficient for the planned usage,
'mail louis@louis‑coder.com if you can't get further sample rates and ‑freq's working).
'
Dim BufferArraySize As Long 'size of buffer for wave data
Dim BufferArray() As Integer 'contains wave data
Private Sub Command1_Click()
'on error resume next
Dim BufferIndex As Long
'preset
BufferArraySize = 44100 * 6&
ReDim BufferArray(1 To BufferArraySize) As Integer
'begin
If GFMicrophoneToArraymod.GFMTA_StartRecording(16, 44100, 0, BufferArraySize * 2&) = False Then '2 bytes for one Integer
MsgBox "Error starting recording !", vbOKOnly + vbCritical
Exit Sub
End If
Debug.Print "STARTING RECORDING FOR 6 SECONDS..."
'Do
Call GFMicrophoneToArraymod.GFMTA_WaitForAnyBufferFill 'wait until sound driver got enough data
BufferIndex = GFMicrophoneToArraymod.GFMTA_GetFilledBufferIndex 'get filled buffer index (an other one is already in use for further recording (if not finished yet))
If BufferIndex = 0 Then Exit Sub 'should not happen
Call GFMicrophoneToArraymod.GFMTA_CatchBuffer(BufferArray(), 1, BufferArraySize * 2&, BufferIndex) 'copy sound data to local array
Call GFMicrophoneToArraymod.GFMTA_ReUseBuffer(BufferIndex) 'reset
'
'NOTE: the recording is now in BufferArray(), you can (manipulate and) replay it, or save it
'to a file using your own writing functions (if you don't need a .wav‑formatted file but just need
'to save the recording for 'private use' (by your program only) then just use the VB functions
'Print #/Get #).
'
'Loop
Debug.Print "RECORDING FINISHED."
Call GFMicrophoneToArraymod.GFMTA_StopRecording 'reset
Exit Sub
End Sub
Private Sub Command2_Click()
'on error resume next
Call GFArrayToSpeakermod.GFATS_StopPlaying 'reset
Call GFArrayToSpeakermod.GFATS_StartPlaying(16, 44100, BufferArraySize * 2&)
'Do
Call GFArrayToSpeakermod.GFATS_WaitForBufferRequiringData
Call GFArrayToSpeakermod.GFATS_SendArray(BufferArray()) 'put in sound data (amplitude values), from recording or any wave generator
'Loop
End Sub
Private Sub Command3_Click()
'on error resume next
Dim Temp As Long
'begin
If (BufferArraySize) Then 'buffer already initialized?
'ok, fill buffer
Else
BufferArraySize = 44100 * 6&
ReDim BufferArray(1 To BufferArraySize) As Integer
End If
For Temp = 1 To BufferArraySize
'NOTE: ugly noise, but just a demonstration ;‑)
BufferArray(Temp) = CLng(Sin(CDbl(Temp) * 0.1)) * 10000& + CLng(Sin(CDbl(Temp) * 0.3)) * 10000& + CLng(Sin(CDbl(Temp) * 0.6)) * 10000&
Next Temp
End Sub
Private Sub Form_Unload(Cancel As Integer)
'on error resume next
'NOTE: call these function when exiting or there may be 'Windows‑specific errors' (bluescreens, mmsystem fall out, etc.)
Call GFArrayToSpeakermod.GFATS_StopPlaying 'reset
Call GFArrayToSpeakermod.GFATS_StopPlaying 'reset
End Sub
[END OF FILE]